package com.scommunity.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scommunity.admin.vo.OwnerQO;
import com.scommunity.domain.Owner;
import com.scommunity.mapper.OwnerMapper;
import com.scommunity.service.IOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OwnerServiceImpl extends ServiceImpl<OwnerMapper, Owner> implements IOwnerService {
    @Autowired
    OwnerMapper ownerMapper;

    @Override
    public PageInfo<Owner> findPageInfoByCondition(OwnerQO ownerQO, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Owner> owners = ownerMapper.findPageInfoByCondition(ownerQO);
        PageInfo<Owner> pageInfo = new PageInfo<>(owners);
        return pageInfo;
    }

    @Cacheable(value = "owners")
    @Override
    public List<Owner> getAll() {
        return ownerMapper.findAll();
    }

    @CacheEvict(value = "owners", allEntries = true)
    @Override
    public void add(Owner owner) {
        ownerMapper.add(owner);
    }

    @CacheEvict(value = "owners", allEntries = true)
    @Override
    public void update(Owner owner) {
        ownerMapper.update1(owner);
    }

    @CacheEvict(value = "owners", allEntries = true)
    @Override
    public void del(String id) {
        ownerMapper.del(id);
    }

    @Override
    public int getStatuseById(String id) {
        return ownerMapper.getStatuseById(id);
    }

    @Override
    public void addOwnerHouse(String ownerId, String houseId) {
        ownerMapper.addOwnerHouse(ownerId, houseId);
    }

    @Override
    public void delOwnerHouse(String ownerId, String houseId) {
        ownerMapper.delOwnerHouse(ownerId, houseId);
    }

    @Override
    public void updateHouseStatusById(String id, String status) {
        ownerMapper.updateHouseStatusById(id, status);
    }

}
